package com.zmx.user.repository;

import com.zmx.common.common.repository.BaseRepository;
import com.zmx.user.entity.MemberCart;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * @author zhaomxr
 */
public interface MemberCartRepository extends BaseRepository<MemberCart> {

    @Query(value = "select * from member_cart WHERE is_vaild = 1 and dr = 0 and member_id = ?1 and product_id = ?2 limit 1", nativeQuery = true)
    MemberCart getCartByMemberIdAndProductId(Long memberId, Long productId);

    void deleteByMemberIdAndProductIdIn(Long memberId, Long[] productIds);

    @Modifying
    @Query(value = "UPDATE member_cart set quantity =?1 WHERE member_id = ?2 and product_id = ?3", nativeQuery = true)
    void updateCart(Integer quantity, Long memberId, Long productId);
}
